package com.reagent.utils;


import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 通用工具类
 * @ClassNmae: FileUtils
 * @Author: HeYue
 * @DateTime: 2020/11/24 17:38
 **/
public class CommonUtils {

    // 获取HttpServletRequest
    public static HttpServletRequest getRequest() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return request;
    }

    // 获取服务器地址
    public static String getServerPath() {
        HttpServletRequest request = getRequest();
        return "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
    }
}
